package com.example.provider;

import com.example.provider.constant.MqConstant;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.junit.jupiter.api.Test;

/**
 * @description: TODO
 * @author: uu
 * @date: 2023/12/15 15:16
 * @version: 1.0
 */
public class Retry {
    @Test
    void retryProducer() throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("retryGroup");
        producer.setNamesrvAddr(MqConstant.NAME_SRV_ADDR);
        producer.start();
        // 生产者重试次数
        producer.setRetryTimesWhenSendFailed(2);
        producer.setRetryTimesWhenSendAsyncFailed(2);
        DefaultMQPushConsumer consumer = new DefaultMQPushConsumer();
        consumer.setMaxReconsumeTimes(2);
        consumer.registerMessageListener((MessageListenerConcurrently) (msg, context) ->{

            return ConsumeConcurrentlyStatus.RECONSUME_LATER;
        });
    }
}
